//
//  RCMessageDetailItemCell.m
//  RocketProject
//
//  Created by chen jiedan on 13-11-18.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCMessageDetailItemCell.h"
#import "CommonDefines.h"
#import "UIColor-Expanded.h"
#import "UIImageView+WebCache.h"

@implementation RCMessageDetailItemCell{
    UIImageView *_imgView;
    UIImageView *_bgImgView;
    
//    UILabel *_nameLabel;
    UILabel *_contentLabel;
    UILabel *_dateLabel;
//    UIView  *horizonLine;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self createPlaceHolder];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}



- (void) createPlaceHolder
{
    _imgView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 30, 30)];
    [self.contentView addSubview:_imgView];
    [_imgView release];
    
    _bgImgView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 30, 30)];
    [self.contentView addSubview:_bgImgView];
    [_bgImgView release];
//    _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 15, 90, 15)];
//    [self.contentView addSubview:_nameLabel];
//    _nameLabel.font = [UIFont fontWithName:kFontNameHeiti size:14];
//    _nameLabel.textColor = kNormalOrangeTextColor;
//    [_nameLabel setBackgroundColor:[UIColor clearColor]];
//    [_nameLabel release];
    
    
    
    _dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 15, 100, 15)];
    [self.contentView addSubview:_dateLabel];
    _dateLabel.font = [UIFont fontWithName:kFontNameHeiti size:12];
    _dateLabel.textColor = kNormalTextColor;
    [_dateLabel setBackgroundColor:[UIColor clearColor]];
    [_dateLabel release];
    
    _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 35, 190, 60)];
    [self.contentView addSubview:_contentLabel];
    _contentLabel.font = [UIFont fontWithName:kFontNameHeiti size:12];
    _contentLabel.textColor = kNormalTextColor;
    _contentLabel.numberOfLines = 0;
    [_contentLabel setBackgroundColor:[UIColor clearColor]];
    [_contentLabel release];
    
    
    
//    horizonLine = [[UIView alloc]initWithFrame:CGRectMake(15, 99, 320-30, 1)];
//    horizonLine.backgroundColor = [UIColor colorWithHex:0xffe6e6e6];
//    [self.contentView addSubview:horizonLine];
//    [horizonLine release];
    
}

- (void) bindData:(RCMessageDetailItemDataModel *)item
{
    [_imgView setImageWithURL:[NSURL URLWithString:item.avatarUrl] placeholderImage:[UIImage imageNamed:@"image_merchant_avatar_default.png"]];
    _contentLabel.text = item.content;
    _dateLabel.text = item.dateTime;
    if (item.isMy) {
        UIImage *t = [UIImage imageNamed:@"rcMessageDetailBG_My"];
        _bgImgView.frame = CGRectMake(10, 10, 270, 50);
        [_bgImgView setImage:[t stretchableImageWithLeftCapWidth:10 topCapHeight:20]];
        _imgView.frame = CGRectMake(280, 10, 30, 30);
        _contentLabel.frame = CGRectMake(20, 15, 260, 15);
        _dateLabel.frame = CGRectMake(20, 40, 120, 15);
    }else{
        _bgImgView.frame = CGRectMake(40, 10, 270, 50);
        UIImage *t = [UIImage imageNamed:@"rcMessageDetailBG_Other"];
        [_bgImgView setImage:[t stretchableImageWithLeftCapWidth:10 topCapHeight:20]];
        _imgView.frame = CGRectMake(10, 10, 30, 30);
        _contentLabel.frame = CGRectMake(60, 15, 300, 30);
        _dateLabel.frame = CGRectMake(60, 40, 120, 15);

    }
//    _nameLabel.text = item.username;
   
    
}


+ (CGFloat) cellHeight:(RCMessageDetailItemDataModel *)item
{
    return 75;
}

@end
